package cn.lingyangwl.agile.system.manager;

import cn.lingyangwl.agile.system.model.entity.SysUserDeptRel;
import cn.lingyangwl.agile.system.mapper.SysUserDeptRelMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author shenguangyang
 */
@Component
public class SysUserDeptRelManager extends ServiceImpl<SysUserDeptRelMapper, SysUserDeptRel> {
    @Resource
    private SysUserDeptRelMapper sysUserDeptRelMapper;


    /**
     * 通过用户和部门的关联ID删除用户信息
     *
     * @param userId 用户和部门的关联ID
     */
    public void deleteByUserId(Long userId) {
        if (Objects.isNull(userId)) {
            return;
        }
        LambdaQueryWrapper<SysUserDeptRel> wrapper = Wrappers.<SysUserDeptRel>lambdaQuery()
                .eq(SysUserDeptRel::getUserId, userId);
        sysUserDeptRelMapper.delete(wrapper);
    }
}
